package service

import (
	"gin/common"
	"gin/model"
	"gin/validate"
)

func CreateWordSpeech(Data validate.AddWordSpeech) (wordSpeechModel model.WordSpeech, err error) {
	wordSpeechModel.Name = Data.Name
	wordSpeechModel.Code = Data.Code
	wordSpeechModel.SourceType = Data.SourceType
	wordSpeechModel.Description = Data.Description
	_, err = wordSpeechModel.Insert()
	return
}

func FindWordSpeech(Param common.SelectQueryParam) (resData model.WordSpeech, err error) {
	var logModel model.WordSpeech

	resData, err = logModel.Find(Param)

	return
}

func SelectWordSpeech(Param common.SelectQueryParam) (total int64, resData []model.WordSpeech, err error) {
	var logModel model.WordSpeech

	total, resData, err = logModel.Select(Param)

	return
}

func UpdateWordSpeech(Data validate.UpdateWordSpeech) (model.WordSpeech, error) {

	var wordSpeech model.WordSpeech

	wordSpeech.Id = Data.Id
	wordSpeech.Name = Data.Name
	wordSpeech.Code = Data.Code
	wordSpeech.SourceType = Data.SourceType
	wordSpeech.Description = Data.Description

	_, err := wordSpeech.Update(&wordSpeech)

	if err != nil {
		return wordSpeech, err
	}

	return wordSpeech.FindById(wordSpeech.Id)
}

// 删除词性说明
func DeleteWordSpeech(Param *common.Filter) {

	var logModel model.WordSpeech
	logModel.DeleteByFilter(Param)
	return
}
